/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.scene.mapper;

import com.koron.hiddendanger.domain.ItemCheckRecord;
import com.koron.scene.bean.CalibrationHistoryView;
import com.koron.scene.bean.CalibrationView;
import com.koron.scene.bean.CheckResultView;
import com.koron.scene.domain.Device;
import com.koron.scene.domain.DeviceCheckRelation;
import org.apache.ibatis.annotations.Param;
import org.koron.ebs.mybatis.EnvSource;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@EnvSource("_default")
public interface DeviceMapper {

    /**
     * insert device
     *
     * @param device
     * @return
     */
    Integer insert(@Param("device") Device device);


    /**
     * insert devices in batch
     *
     * @param deviceList
     * @return
     */
    Integer batchInsert(@Param("deviceList") List<Device> deviceList);


    /**
     * delete devices in batch
     *
     * @param idList
     * @return
     */
    Integer batchDetele(@Param("idList") List<String> idList);


    /**
     * update one device
     *
     * @param device
     * @return
     */
    Integer update(@Param("device") Device device);

    /**
     * query the one whose id is the given
     *
     * @param id
     * @return
     */
    Device queryOne(@Param("id") String id);


    /**
     * fetch all devices in the given condition
     *
     * @param gridCode
     * @param deviceName
     * @param checkEmployeeName
     * @param calibrationExpiredDate
     * @param start
     * @param rows
     * @return
     */
    List<Device> queryByCondition(@Param("corpCode") String corpCode, @Param("gridCode") String gridCode, @Param("deviceName") String deviceName, @Param("deviceTypeId") String deviceTypeId,
                                  @Param("deptName") String deptName, @Param("checkEmployeeName") String checkEmployeeName, @Param("calibrationExpiredDate") Timestamp calibrationExpiredDate, @Param("status") Integer status,
                                  @Param("start") Integer start, @Param("rows") Integer rows);


    List<Device> queryByConditionAll(@Param("corpCode") String corpCode, @Param("gridCode") String gridCode, @Param("deviceName") String deviceName, @Param("deviceTypeId") String deviceTypeId,
                                  @Param("deptName") String deptName, @Param("checkEmployeeName") String checkEmployeeName, @Param("calibrationExpiredDate") Timestamp calibrationExpiredDate, @Param("status") Integer status,
                                  @Param("start") Integer start, @Param("rows") Integer rows ,  @Param("keyword") String keyword);

    Integer countByConditionAll(@Param("corpCode") String corpCode, @Param("gridCode") String gridCode, @Param("deviceName") String deviceName, @Param("deviceTypeId") String deviceTypeId,
                             @Param("deptName") String deptName, @Param("checkEmployeeName") String checkEmployeeName, @Param("calibrationExpiredDate") Timestamp calibrationExpiredDate, @Param("status") Integer status,
                              @Param("keyword") String keyword);
    /**
     * query relation
     *
     * @param deviceCheckRecordId
     * @param deviceId
     * @return
     */
    DeviceCheckRelation queryRelation(@Param("deviceCheckRecordId") String deviceCheckRecordId, @Param("deviceId") String deviceId);

    /**
     * save relation between check and device
     *
     * @param relationList
     * @return
     */
    Integer batchInsertRelation(@Param("relationList") List<DeviceCheckRelation> relationList);


    /**
     * update relation
     *
     * @param relation
     * @return
     */
    Integer updateRelation(@Param("relation") DeviceCheckRelation relation);

    /**
     * query device check result
     *
     * @param checkEmployeeCode
     * @param deviceCheckRecordId
     * @param start
     * @param rows
     * @return
     */
    List<Device> queryDeviceInCheck(@Param("checkEmployeeCode") String checkEmployeeCode, @Param("deviceCheckRecordId") String deviceCheckRecordId,
                                    @Param("start") Integer start, @Param("rows") Integer rows);



    /**
     * query calibration result
     *
     * @param responsibleEmployeeCode
     * @param deviceCalibrationId
     * @param start
     * @param rows
     * @return
     */
    List<CalibrationView> queryDeviceInCalibration(@Param("responsibleEmployeeCode") String responsibleEmployeeCode, @Param("deviceCalibrationId") String deviceCalibrationId,
                                                   @Param("start") Integer start, @Param("rows") Integer rows);

    List<CheckResultView> queryAssociatedCheck(@Param("deviceId") String deviceId, @Param("start") Integer start, @Param("rows") Integer rows);

    Integer countAssociatedCheck(@Param("deviceId") String deviceId);


    List<CalibrationHistoryView> queryAssociatedCalibration(@Param("deviceId") String deviceId, @Param("start") Integer start, @Param("rows") Integer rows);

    Integer countAssociatedCalibration(@Param("deviceId") String deviceId);


    List<Device> queryForCheckEmployee(@Param("corpCode") String corpCode, @Param("checkEmployeeCode") String checkEmployeeCode, @Param("start") Integer start, @Param("rows") Integer rows);

    Integer countForCheckEmployee(@Param("corpCode") String corpCode, @Param("checkEmployeeCode") String checkEmployeeCode);


    List<CalibrationView> queryResponsibleEmployee(@Param("corpCode") String corpCode, @Param("responsibleEmployeeCode") String responsibleEmployeeCode, @Param("deviceCalibrationId") String deviceCalibrationId, @Param("start") Integer start, @Param("rows") Integer rows);


    Integer countResponsibleEmployee(@Param("corpCode") String corpCode, @Param("responsibleEmployeeCode") String responsibleEmployeeCode, @Param("deviceCalibrationId") String deviceCalibrationId);


    List<CalibrationView> queryForResponsibleEmployee(@Param("corpCode") String corpCode, @Param("responsibleEmployeeCode") String responsibleEmployeeCode, @Param("start") Integer start, @Param("rows") Integer rows);

    /**
     * 根据id 修改 设置台账 最近检查日期
     *
     * @param id
     * @param lastCheckDate 最近检查日期
     * @return
     */
    Integer updateLastCheckDateById(@Param("id") String id, @Param("lastCheckDate") Date lastCheckDate);

    /**
     * 根据id 修改 设置台账 最近校验日期
     *
     * @param id
     * @param lastCalibrationDate 最近校验日期
     * @return
     */
    Integer updateLastCaliDateById(@Param("id") String id, @Param("lastCalibrationDate") Timestamp lastCalibrationDate);

    /**
     * 根据水司code和检验记录id查询是否存在检查明细信息
     *
     * @param corpCode
     * @param deviceCalibrationId
     * @return
     */
    Integer queryCalibrationRelation(@Param("corpCode") String corpCode, @Param("deviceCalibrationId") String deviceCalibrationId);

    /**
     * 根据检验记录id和设备id删除检查明细信息
     *
     * @param deviceCalibrationId
     * @param deviceId
     * @return
     */
    Integer deleteCalibrationRelation(@Param("deviceCalibrationId") String deviceCalibrationId, @Param("deviceId") String deviceId);

    Integer batchInsertCheckEntryItem(@Param("itemList")List<ItemCheckRecord> itemList);

    Integer deleteCheakEntryItem(@Param("deviceCheckRecordId")String deviceCheckRecordId, @Param("checkListEntryId")String checkListEntryId);

    List<ItemCheckRecord> queryCheckListEntry(@Param("deviceCheckRecordId")String deviceCheckRecordId, @Param("checkListEntryId")String checkListEntryId);

    List<Device> queryAll();

    Integer batchUpdateNoticeState(@Param("idList") List<String> idList, @Param("noticeState") Integer noticeState);

    Device queryOneCheckEmployee(@Param("corpCode")String corpCode, @Param("checkEmployeeCode")String checkEmployeeCode, @Param("deviceId")String deviceId);

    CalibrationView queryOneResponsibleEmployee(@Param("corpCode")String corpCode, @Param("responsibleEmployeeCode")String responsibleEmployeeCode, @Param("deviceCalibrationId")String deviceCalibrationId, @Param("deviceId")String deviceId);

    List<CalibrationView> queryOneDeviceInCalibration(@Param("responsibleEmployeeCode")String responsibleEmployeeCode, @Param("deviceCalibrationId")String deviceCalibrationId, @Param("deviceId")String deviceId);
}
